//引入刚才的http.js文件
import https from './https.js';

export default {
    // 导出表格
    /**
     * 
     * @param {*} jsonData 表格数据
     * @param {*} tit 表格头
     * @param {*} excel 表格名称
     * @returns 
     */
    exportData: function (jsonData, tit, excel) {
        if (!jsonData.length) {
            return false;
        }

        // 表格的列标题 如果出现科学技术法或者其他格式 使用 \t
        let title = tit;
        jsonData.map((item, index) => {
            let obj = {};
            for (const key in item) {
                const element = item[key];
                obj[index] = element;
                for (let i in obj) {
                    title += `${obj[i]},`;
                }
            }
            title += "\n";
        });
        // encodeURIComponent 解决中文乱码
        let url =
            "data:text/csv;charset=utf-8,\ufeff" + encodeURIComponent(title);
        // 创建a标签
        let link = document.createElement("a");
        link.href = url;
        link.download = `${excel}${new Date().toJSON()}.xls`;
        link.click();
        link.remove();
    },
    testGet: function (params) {
        return https.get('/', params)
    },
    testPost: function (params) {
        return https.post('/post', params)
    },
    login: function (params) {
        return https.post('/api/auth/guild_login', params)
    },
    out_list: function (params) { // 公会申请退出列表
        return https.get('/api/guild_backend/out_list', params)
    },
    // 文件上传
    upload: function (params) {
        return https.post('/api/file/upload_guild', params)
    },
}